<!DOCTYPE html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no">
    <!-- Start of Baidu Transcode -->
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
    <meta http-equiv="Pragma" content="no-cache" />
    <meta http-equiv="Expires" content="0" />
    <meta name="applicable-device" content="pc,mobile">
    <meta name="MobileOptimized" content="width"/>
    <meta name="HandheldFriendly" content="true"/>
    <meta name="mobile-agent" content="format=html5;">
    <!-- End of Baidu Transcode -->

    <meta name="description" content="欢迎来到西安交大深圳MEM2018年会现场！">

    <!-- Apple -->
    <meta name="apple-mobile-web-app-title" content="西安交大深圳MEM2018年会">
    <title>西安交大深圳MEM2018年会</title>
    <link rel="stylesheet" media="all" href="index.css"/>

    <link rel="stylesheet" media="all" href="style.css"/>

    <script src="jquery-1.8.0.js"></script>
    <script src="jquery.form.js"></script>

    <style type="text/css">

    </style>

</head>

<body class="no-padding reader-black-font" lang="zh-CN">
<div class="sign">
    <div class="main">
        <h4 class="title">
            <div class="normal-title">
                <a id="js-sign-btn" class="active" href="javascript:void 0">签到</a>
                <b>·</b>
                <a id="js-speak-btn" class="" href="speak.html">发弹幕</a>
            </div>
        </h4>
        <div class="js-sign-up-container">
            <form class="new_user" id="new_user"
                  accept-charset="UTF-8" method="post">
                <div class="input-prepend restyle">
                    <input placeholder="您的姓名" type="text" value="" name="name" required id="user_username"/>
                </div>

                <div class="input-prepend restyle no-radius js-normal">
                    <input placeholder="手机号" type="tel" name="mobile" required id="user_mobile_number"/>
                </div>
                <div class="input-prepend restyle no-radius js-security-number">
                    <input type="text" name="smsCode" id="sms_code" required placeholder="手机验证码"/>
                    <a tabindex="-1" class="btn-up-resend js-send-code-button" id="smsBtn" href="javascript:void 0">发送验证码</a>
                </div>
                <div class="input-prepend">
                    <input placeholder="班级" type="text" name="className" required id="user_class"/>
                </div>

                <div class="input-prepend">
                    <input placeholder="留言" type="text" name="message" id="user_message"/>
                </div>
                <div id="alertDiv" class="alert alert-info text-left" style="display: none;color:red;">
                    Indicates a neutral informative change or action.
                </div>
                <input type="submit" value="提交" class="sign-up-button" id="submitBtn" data-disable-with="提交"/>
            </form>
        </div>
    </div>
</div>
<script src="base.js"></script>
<script type="text/javascript">

    window.onload = function () {
        var smsBtn = document.getElementById("smsBtn");

        smsBtn.onclick = function () {

            var telphone = document.getElementById("user_mobile_number").value;
            if (telphone.length != 11) {
                $("#alertDiv").text("请输入正确的手机号!")
                $("#alertDiv").show()
                return
            }
            else {
                settime(smsBtn, 60)
                var smsObject = {"mobile": telphone};
                $.ajax({
                    url: baseUrl + "smscode",
                    dataType: "json",
                    success: function (data) {
                        $("#alertDiv").text("验证码已发送，请查收!")
                        $("#alertDiv").show()
                    },
                    error: function (data, textStatus, errorThrown) {
                        /*     alert("error");
                             alert(data);
                             alert(data.status);
                             alert(data.readyState);
                             alert(textStatus);
                             alert(errorThrown);*/
                    },
                    type: "post",
                    contentType: "application/x-www-form-urlencoded;",
                    data: smsObject
                });
            }
            ;
        }
    }

    function settime(val, countdown) {
        if (countdown == 0) {
            val.removeAttribute("disabled");
            val.innerText = "重新获取验证码";
            return;
        } else {
            val.setAttribute("disabled", true);
            val.innerText = "重新发送(" + countdown + ")";
            countdown--;
        }
        setTimeout(function () {
            settime(val, countdown);
        }, 1000);
    }

    //    action="http://www.thoughtmocks.com:8080/api/sign"
    var options = {
        url: baseUrl + "sign",
        success: function (data) {
//            var resultJson = JSON.parse(data);
            var resultJson = data;
            if (resultJson.result == true) {
                //alert("Thank you for your comment!");
                location.href = "signsuccess.html";
            }
            else {
                $("#alertDiv").text(resultJson.msg)
                $("#alertDiv").css("color","red")
                $("#alertDiv").show()
            }
        },
        error: function (data) {
            8
        }
    };

    // wait for the DOM to be loaded
    $(document).ready(function () {
        $('#new_user').ajaxForm(options);
    });
</script>
</body>
</html>